const http = require('../../../utils/http.js')

Page({

    /**
     * 页面的初始数据
     */
    data: {
        imgUrl: http.imgUrl,
        navBar: {
            title: '敏捷项目管理',
            btn: 'goBack'
        },
        stars: [0, 1, 2, 3, 4],
        normalSrc: http.imgUrl + 'icon_star_empty_large.png',
        selectedSrc: http.imgUrl + 'icon_star_full_large.png',
        halfSrc: http.imgUrl + 'icon_star_half_large.png',
        score: 5,
    },

    /**
     * 返回
     */
    goBack() {
        http.goBack()
    },

    /**
     * 获取评价内容
     */
    inputTxt(e) {
        this.setData({
            eval: e.detail.value
        })
    },

    /**
     * 改变星级评分
     */
    starLeft(e) {
        let score = e.currentTarget.dataset.score
        if (this.data.score == 0.5 && e.currentTarget.dataset.score == 0.5) {
            score = 0
        }
        this.setData({
            score: score
        })
    },
    starRight(e) {
        let score = e.currentTarget.dataset.score
        this.setData({
            score: score
        })
    },

    /**
     * 发布评分
     */
    confirmScore() {
        let that = this,
            url = 'Lesson_lessonStar',
            token = wx.getStorageSync('token'),
            lid = that.data.lid,
            star_number = that.data.score,
            content = that.data.eval

        // console.log(lid)

        if (!http.ifEmpty(content)) {
            wx.showToast({
                title: '请输入评价内容',
                icon: 'none',
                duration: 3000
            })

            return
        }

        http._post(
            url,
            { token: token, lid: lid, star_number: star_number, content: content },
            res => {
                console.log(res.data)
                wx.showToast({
                    title: res.data.info,
                    icon: 'none',
                    duration: 3000
                })
                if (res.data.re === '1') {
                    that.goBack()
                }
            },
            err => {
                console.log(err)
            }
        )
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            lid: options.id || 0
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})